﻿Partial Public Class WebFormAnsprechpartner
    Inherits System.Web.UI.Page
    Public _db As New hc_databaseDataContext

    Public Artlist() As String


    Protected Sub page_load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load, Me.Load
        GVAnsprech.DataBind()
        Try
            GVAnsprech.SelectedIndex = 0

            Session("AnsprechID") = GVAnsprech.SelectedRow.Cells.Item(0).Text
            GridView1.DataBind()

            'Dim kid = Session("KundeID")
            'Dim ansprechlist = (From AID In _db.Ansprechpartner Where AID.Kunde_id = kid).ToArray

            'Session("AnsprechID") = ansprechlist(GVAnsprech.SelectedIndex)

            'GridView1.DataBind()

        Catch ex As Exception

        End Try
        Dim KID As Integer = Session("KundeID")


        Dim kundenname = (From K In _db.Kundes Where K.ID = KID Select K.Name).First

        '   formviewdetail.DataBind()

        Label1.Text = "Ansprechpartner und Kontakthistorie von " & kundenname


    End Sub


    Protected Sub btnAnsprechNeu_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAnsprechNeu.Click
        Dim KID As Integer = Session("KundeID")

        Dim ord As New Ansprechpartner With {.Vorname = VornameTextBox.Text, _
                                             .Nachname = NachnameTextBox.Text, _
                                             .Telefonnummer = TelefonnummerTextBox.Text, _
                                             .Fax = FaxTextBox.Text, _
                                             .email = emailTextBox.Text, _
                                             .Kunde_id = KID}

        _db.Ansprechpartners.InsertOnSubmit(ord)

        _db.SubmitChanges()

        GVAnsprech.DataBind()


        VornameTextBox.Text = ""
        NachnameTextBox.Text = ""
        TelefonnummerTextBox.Text = ""
        FaxTextBox.Text = ""
        emailTextBox.Text = ""

    End Sub

    Protected Sub btnKontaktNeu_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnKontaktNeu0.Click

        Dim AID As Integer = Session("AnsprechID")

        Dim ord As New Kundenkontakt With {.ArtKontakt = ArtTextBox0.Text, _
                                           .Betreff = BetreffTextBox0.Text, _
                                           .Datum = DatumTextBox0.Text, _
                                           .AnsprechpartnerID = AID, _
                                           .Inhalt = InhaltTextBox0.Text}



        _db.Kundenkontakts.InsertOnSubmit(ord)

        _db.SubmitChanges()

        GridView1.DataBind()


        ArtTextBox0.Text = ""
        BetreffTextBox0.Text = ""
        DatumTextBox0.Text = ""
        InhaltTextBox0.Text = ""


    End Sub

    Protected Sub GVAnsprech_SelectedIndexChanged() Handles GVAnsprech.SelectedIndexChanged
        Session("AnsprechID") = GVAnsprech.SelectedRow.Cells.Item(0).Text
        GridView1.DataBind()

        lblKundenkontakt.Text = "Kontakte mit " & GVAnsprech.SelectedRow.Cells.Item(1).Text & GVAnsprech.SelectedRow.Cells.Item(2).Text


        'lblKundenkontakt.Text = "Kontakte mit " & GVAnsprech.SelectedRow.Cells.Item(1).Text & GVAnsprech.SelectedRow.Cells.Item(2).Text

    End Sub
End Class